<!-- 公共search -->
<template>
<div class="main">
  <div class="search-container">
    <div class="close">
      <el-button icon="el-icon-close" circle type="danger" size="mini" @click="searchBack"></el-button>
    </div>
    <div class="operation">
      <div class="title">{{label}}</div>
      <div>
        <el-button size="mini" type="primary" icon="el-icon-search" @click="submit">查询</el-button>
        <el-button size="mini" type="danger" @click="clear">清除</el-button>
        <el-button size="mini" @click="searchBack">取消</el-button>
      </div>
    </div>
    <el-form class="form" ref="form" :model="formData" label-width="130px" size="mini" status-icon>
      <template v-for="(item, index) of condiItems">
        <el-row style="display: flex; flex-direction: row; align-items: center; width: 100%; border-top: 1px solid #e7e7e7;border-bottom: 1px solid #e7e7e7;" @click.native="selectOne(index)">
          <el-checkbox @click.stop.native v-model="item.checked" @change="(item)" name="type"  class="search-checkbox"></el-checkbox>
          <el-form-item class="form-item" :label="item.name" :required="item.required" style="width: 400px;">
            <!-- 单个输入 -->
            <el-input v-if="item.type == 'text'" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
            <!-- 一行多个输入 -->
            <el-row v-if="item.type=='multi-text'">
              <el-col :span="textItem.span" v-for="(textItem,index) of item.texts" :key="index">
                <el-input :placeholder="textItem.placeholder" v-model="formData[textItem.key]">
                  <template v-if="textItem.name" slot="append">{{textItem.name}}</template>
                </el-input>
              </el-col>
            </el-row>
            <!-- 搜索的输入框 -->
            <el-input v-if="item.type=='search'" readonly :placeholder="item.placeholder" v-model="formData[item.key]">
              <el-button slot="append" icon="el-icon-search" @click="search(item)"></el-button>
            </el-input>
            <el-input type="textarea" :disabled="disabled || item.disable" v-if="item.type == 'textarea'" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
            <!-- 单选 -->
            <el-select loading-text="加载中" class="single" v-if="item.type == 'single-select'" v-model="formData[item.key]" placeholder="请选择" @focus="getSelectOption(item)">
              <el-option v-for="(option, index) of item.options" :key="index" :label="option.name" :value="option.value"></el-option>
            </el-select>
            <!-- checkbox -->
            <el-checkbox v-if="item.type=='checkbox'" v-model="formData[item.key]" name="type"></el-checkbox>
          </el-form-item>
        </el-row>
      </template>
      <el-checkbox label="满足全部条件" v-model="allchecked" @change="selectAll" class="search-checkbox"></el-checkbox>
      <el-divider class="search-divider"></el-divider>
    </el-form>
    <CommonList v-if="columns && columns.length > 0" ref="listView" :columns="cols" :listUrl="listUrl" :conditions="cons" @tableSelect="tableSelect"></CommonList>
    <CommonSearch :label="item.label"
                  :conditions="item.conditions"
                  v-for="(item, index) of searchs"
                  :key="index"
                  :listUrl="item.listUrl"
                  :columns="item.columns"
                  :items="item.items"
                  @search="search"
                  @submit="item.selectItem"
                  @searchBack="searchBack"/>
  </div>
</div>
</template>

<script>
import http from '../../api/http'
import CommonList from "./CommonList";
export default {
  name: 'CommonSearch',
  props: {
    listUrl: String,
    items: {
      type: Array,
      default() {
        return []
      }
    },
    columns:{
      type: Array,
      default() {
        return []
      }
    },
    label: String,
    originalData: Object,
    conditions: Array,
    page: {
      type: String,
      default() {
        return null
      }
    },
    pageType: {
      type: Number,
      default() {
        return 0
      }
    },
  },
  data() {
    return {
      allchecked: false,
      searchs: [],
      formData: this.originalData ? this.originalData : {},
      data: [],
      cols: this.columns.map(item => { item.minWidth = item.label.length * 18; return item}),
      condiItems: [],
      tableHeaders: this.headers,
      cons: this.conditions,
      storeItems: [
      {
        name: '门店名称',
        key: 'retailName',
        type: 'text',
      },
      {
        name: '统一编码',
        key: this.pageType < 0 ? 'mdmCode' : 'mdmCode',
        key1: 'mdmCode',
        type: 'text',
      },
      {
        name: '外部系统编码',
        key: 'code',
        type: 'text',
      },
      {
        name: '数据来源',
        key: 'dataSource',
        type: 'text',
      },
      {
        name: 'JDESCode',
        key: this.pageType < 0 ? 'jDESCode' : 'jdesCode',
        type: 'text',
      },
      {
        name: 'TPCode',
        key: this.pageType < 0 ? 'tpCode' : 'tpCode',
        type: 'text',
      },
      {
        name: 'SFACode',
        key: this.pageType < 0 ? 'sfaCode' : 'sfaCode',
        type: 'text',
      },
      {
        name: 'Region',
        key: 'zoneName',
        vkey: this.pageType < 0 ? 'fkZone' : 'region',
        type: 'search',
      },
      {
        name: 'Area',
        key: 'regionName',
        vkey: this.pageType < 0 ? 'fkRegion' : 'area',
        type: 'search',
      },
      {
        name: '省份',
        key: 'province',
        type: 'text',
      },
      {
        name: '城市',
        key: 'physicalCity',
        type: 'text',
      },
      {
        name: '客户集团',
        key: 'customNameCn',
        vkey: 'fkRetailGroup',
        type: 'search',
      },
      {
        name: '是否LKA',
        key: 'isLKA',
        type: 'checkbox',
      },
      {
        name: '门店类型',
        key: 'retailType',
        vkey: 'fkRetailType',
        type: 'search',
      },
      {
        name: 'location',
        key: 'locationName',
        vkey: 'fkLocation',
        type: 'search',
      },
      {
        name: '门店投资属性',
        key: 'retailLevelName',
        vkey: 'fkLevel',
        type: 'search',
      },
      {
        name: '营业状态',
        key: 'businessStatus',
        type: 'text',
      },
      {
        name: '合作状态',
        key: 'cooperationStatus',
        type: 'text',
      },
      {
        name: 'Remark',
        key: 'remark',
        type: 'text',
      },
      {
        name: '是否Promoter覆盖',
        key: 'isPromoter',
        type: 'checkbox',
      },
      {
        name: '是否B2B生意覆盖',
        key: 'isB2b',
        type: 'checkbox',
      },
      {
        name: '是否销售强生商品',
        key: 'isSalesjnj',
        type: 'checkbox',
      },
      {
        name: '是否有效',
        key: 'isValid',
        type: 'checkbox',
      },
      {
        name: '负责人',
        key: 'repName',
        vkey: 'fkRep',
        type: 'search',
      },
      ],
      customerItems:[
      {
          name: '统一编码',
          key: 'smmsCode',
          type: 'text',
        },
        {
          name: '客户编码',
          key: 'soldToCode',
          type: 'text',
        },
        {
          name: '客户名称',
          key: 'smmsName',
          type: 'text',
        },
        {
          name: '客户属性',
          key: 'levelName',
          vkey: 'fkDealerLevel',
          type: 'search',
        },
        {
          name: 'Region',
          key: 'zoneName',
          vkey: 'region',
          type: 'search',
        },
        {
          name: 'Area',
          key: 'regionName',
          vkey: 'area',
          type: 'search',
        },
        {
          name: '省份',
          key: 'province',
          type: 'text',
        },
        {
          name: '城市',
          key: 'physicalCity',
          type: 'text',
        },
        {
          name: '适用品牌',
          key: 'brandName',
          vkey: 'fkBrand',
          type: 'search',
        },
        {
          name: 'Destination',
          key: 'destinationName',
          vkey: 'fkDestination',
          type: 'search',
        },
        {
          name: '供货方',
          key: 'smmsOwnerName',
          vkey: 'fkOwner',
          type: 'search',
        },
        {
          name: '客户集团',
          key: 'customNameCn',
          vkey: 'fkCustom',
          type: 'search',
        },
        {
          name: '是否LKA',
          key: 'isLKA',
          type: 'checkbox',
        },
        {
          name: '营业状态',
          key: 'businessStatus',
          type: 'text',
        },
        {
          name: '合作状态',
          key: 'cooperationStatus',
          type: 'text',
        },
        {
          name: '客户负责人',
          key: 'repName',
          vkey: 'fkRep',
          type: 'search',
        },
        {
          name: '业务单位',
          key: 'buName',
          vkey: 'fkBu',
          type: 'search',
        },
        {
          name: '数据来源',
          key: 'dataSource',
          type: 'text',
        }
      ],
      retailerList:[]
    }
  },
  methods: {
    search(item) {
      console.log(this.page)
      if (this.page == "customer" || this.page == "store") {
        let self = this
        let callback = (obj) => {
          // 已绑定的对象不允许动态添加属性，添加了也不会生成setter和getter
          let data = Object.assign({}, this.formData)
          data = Object.assign(data, obj)
          self.formData = data
        }
        if (item.key == 'smmsOwnerName') {
          // 供货方
          this.searchs.push({
            label: '客户信息',
            conditions: [{checked: true, prop: 'pageType', value: '9'},{checked: true, prop: 'fkDealerLevel'}],
            listUrl: this.$api.API_SMMS_DEALER_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof callback == 'function') {
                let data = {smmsOwnerCode: resp.smmsCode}
                data[item.key] = resp.smmsName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '客户名称',
              key: 'smmsName',
              type: 'text',
            },{
              name: 'SoldToCode',
              key: 'soldToCode',
              type: 'text',
            },{
              name: '统一编码',
              key: 'smmsCode',
              type: 'text',
            },{
              name: '客户属性',
              key: 'levelName',
              type: 'search',
            },{
              name: '客户集团',
              key: 'customNameCn',
              vkey: 'fkCustom',
              type: 'search',
            },{
              name: '客户负责人',
              key: 'repName',
              vkey: 'fkRep',
              type: 'search',
            }],
            columns: [{
              prop: 'smmsName',
              label: '客户名称'
            },{
              prop: 'soldToCode',
              label: 'SoldToCode'
            },{
              prop: 'smmsCode',
              label: '统一编码'
            },{
              prop: 'levelName',
              label: '客户属性'
            },{
              prop: 'customNameCn',
              label: '客户集团'
            },{
              prop: 'repName',
              label: '客户负责人'
            }]
          })
        } else if (item.key == 'levelName') {
          // 客户属性
          this.searchs.push({
            label: '客户属性管理',
            conditions: [],
            listUrl: this.$api.API_CUSTOMERTYPE,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.levelName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '客户属性名称',
              key: 'levelName',
              type: 'text',
            },{
              name: '客户属性代码',
              key: 'levelCode',
              type: 'text',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'levelName',
              label: '客户属性名称'
            },{
              prop: 'levelCode',
              label: '客户属性代码'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'repName') {
          // 客户属性
          this.searchs.push({
            label: '人员信息',
            conditions: [],
            listUrl: this.$api.API_GETTPINFO_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.repName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '员工姓名',
              key: 'repName',
              type: 'text',
            },{
              name: '员工账号',
              key: 'repCode',
              type: 'text',
            },{
              name: '所属管理层级',
              key: 'positionName',
              vkey: 'fkPosition',
              type: 'search',
            },{
              name: 'WWID',
              key: 'wWID',
              type: 'text',
            },{
              name: 'SAP代码',
              key: 'sapCode',
              type: 'text',
            },{
              name: '总部/大区',
              key: 'hQOrRegion',
              type: 'text',
            }],
            columns: [{
              prop: 'repName',
              label: '员工姓名'
            },{
              prop: 'repCode',
              label: '员工账号'
            },{
              prop: 'positionName',
              label: '所属管理层级'
            },{
              prop: 'WWID',
              label: 'wWID'
            },{
              prop: 'sapCode',
              label: 'SAP代码'
            },{
              prop: 'hQOrRegion',
              label: '总部/大区'
            }]
          })
        } else if (item.key == 'customNameCn') {
          // 客户集团
          this.searchs.push({
            label: '客户集团',
            conditions: [],
            listUrl: this.$api.API_SELECT_CUSTOMER_GROUP_INFO,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.customNameCN
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '集团中文名称',
              key: 'customNameCN',
              type: 'text',
            },{
              name: 'Destination',
              key: 'destinationName',
              type: 'text',
            },{
              name: '集团英文名称',
              key: 'customNameEN',
              type: 'text',
            },{
              name: '预算Account',
              key: 'accountCode',
              type: 'text',
            },{
              name: '客户集团分类',
              key: 'customTypeName',
              vkey: 'fkCustomType',
              type: 'search',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'customNameCN',
              label: '集团中文名称'
            },{
              prop: 'destinationName',
              label: 'Destination'
            },{
              prop: 'customNameEN',
              label: '集团英文名称'
            },{
              prop: 'accountCode',
              label: '预算Account'
            },{
              prop: 'customTypeName',
              label: '客户集团分类'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if(item.key == 'isLKAvalue') {
          this.searchs.push({
            label: '是否LKA',
            conditions: [],
            listUrl: this.$api.API_COMMON_ISLKA_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.isLKAvalue
                if (item.vkey) {
                  data[item.vkey] = resp.isLKA
                }
                callback(data)
              }
            },
            items: [],
            columns: []
          })
        } else if (item.key == 'positionName') {
          // 职位信息
          this.searchs.push({
            label: '职位信息',
            conditions: [],
            listUrl: this.$api.API_MANAGEMENTHIERARCHY_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.positionName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '职位名称',
              key: 'positionName',
              type: 'text',
            },{
              name: '职位代码',
              key: 'positionCode',
              type: 'text',
            }],
            columns: [{
              prop: 'positionName',
              label: '职位名称'
            },{
              prop: 'createTime',
              label: '创建时间'
            },{
              prop: 'modifyTime',
              label: '最后修改时间'
            },{
              prop: 'valid',
              label: '是否有效'
            },{
              prop: 'positionCode',
              label: '职位代码'
            }]
          })
        } else if (item.key == 'customTypeName') {
          // 客户集团分类
          this.searchs.push({
            label: '客户集团分类',
            conditions: [],
            listUrl: this.$api.API_CUSTOMERCLASSIFY_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.customTypeName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '集团类型编码',
              key: 'customTypeCode',
              type: 'text',
            },{
              name: '集团类型名称',
              key: 'customTypeName',
              type: 'text',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'customTypeCode',
              label: '集团类型编码'
            },{
              prop: 'customTypeName',
              label: '集团类型名称'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'destinationName') {
          // Destination类型
          this.searchs.push({
            label: 'Destination类型',
            conditions: [],
            listUrl: this.$api.API_DESTINATION_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.destinationName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: 'Destination编码',
              key: 'destinationCode',
              type: 'text',
            },{
              name: 'Destination名称',
              key: 'destinationName',
              type: 'text',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'destinationCode',
              label: 'Destination编码'
            },{
              prop: 'destinationName',
              label: 'Destination名称'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'zoneName') {
          // 大区信息
          this.searchs.push({
            label: '大区信息',
            conditions: [],
            listUrl: this.$api.API_QUERYZONE,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.zoneName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '大区名称',
              key: 'zoneName',
              type: 'text',
            },{
              name: '大区代码',
              key: 'zoneCode',
              type: 'text',
            }],
            columns: [{
              prop: 'zoneName',
              label: '大区名称'
            },{
              prop: 'zoneCode',
              label: '大区代码'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'regionName') {
          // 区域信息
          this.searchs.push({
            label: '区域信息',
            conditions: [],
            listUrl: this.$api.API_QUERYREGION,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.regionName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '区域名称',
              key: 'regionName',
              type: 'text',
            },{
              name: '区域代码',
              key: 'regionCode',
              type: 'text',
            },{
              name: '所属大区',
              key: 'zoneName',
              vkey: 'fkZone',
              type: 'search',
            }],
            columns: [{
              prop: 'regionName',
              label: '区域名称'
            },{
              prop: 'regionCode',
              label: '区域代码'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'brandName') {
          // 适用品牌
          this.searchs.push({
            label: '适用品牌',
            conditions: [],
            listUrl: this.$api.API_APPLYBRADN_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.brandName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '适用品牌代码',
              key: 'brandCode',
              type: 'text',
            },{
              name: '适用品牌名称',
              key: 'brandName',
              type: 'text',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'brandCode',
              label: '适用品牌代码'
            },{
              prop: 'brandName',
              label: '适用品牌名称'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'buName') {
          // 业务单位管理
          this.searchs.push({
            label: '业务单位管理',
            conditions: [],
            listUrl: this.$api.API_BUSETTING_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.buName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '业务单位名称',
              key: 'buName',
              type: 'text',
            },{
              name: '业务单位编码',
              key: 'buCode',
              type: 'text',
            },{
              name: '是否有效',
              key: 'isValid',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'buName',
              label: '业务单位名称'
            },{
              prop: 'buCode',
              label: '业务单位编码'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'retailType') {
          // 门店类型管理
          this.searchs.push({
            label: '门店类型管理',
            conditions: [],
            listUrl: this.$api.API_SELECT_RETAIL_TYPE_INFO,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.retailName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '门店类型名称',
              key: 'retailName',
              type: 'text',
            },{
              name: '门店类型代码',
              key: 'retailCode',
              type: 'text',
            },{
              name: '排序',
              key: 'sortCode',
              type: 'checkbox',
            }],
            columns: [{
              prop: 'retailName',
              label: '门店类型名称'
            },{
              prop: 'retailCode',
              label: '门店类型代码'
            },{
              prop: 'sortCode',
              label: '排序'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'locationName') {
          // location管理
          this.searchs.push({
            label: 'location管理',
            conditions: [],
            listUrl: this.$api.API_COMMON_LOCATION_INFO,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.locationName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [
              {
              name: 'location代码',
              key: 'locationCode',
              type: 'text',
              },
              {
              name: 'location名称',
              key: 'locationName',
              type: 'text',
            }],
            columns: [{
              prop: 'locationCode',
              label: 'location代码'
            },{
              prop: 'locationName',
              label: 'location名称'
            }]
          })
        } else if (item.key == 'retailLevelName') {
          // 门店投资属性
          this.searchs.push({
            label: '门店投资属性',
            conditions: [],
            listUrl: this.$api.API_SELECT_RETAIL_LEVEL_INFO,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.levelName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [{
              name: '投资属性名称',
              key: 'levelName',
              type: 'text',
            },{
              name: '投资属性代码',
              key: 'levelCode',
              type: 'text',
            }],
            columns: [{
              prop: 'levelName',
              label: '投资属性名称'
            },{
              prop: 'levelCode',
              label: '投资属性代码'
            },{
              prop: 'valid',
              label: '是否有效'
            }]
          })
        } else if (item.key == 'parentName') {
          this.searchs.push({
            label: '主管',
            conditions: [],
            listUrl: this.$api.API_Leader_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.repNameCn
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [
              {
                key:'repNameCn',
                name:'姓名',
                search:true,
                type:'text'
            },
            {
                key:'wwid',
                name:'WWID',
                search:true,
                type:'text'
            }],
            columns: [{
              prop: 'repNameCn',
              label: '姓名'
            },{
              prop: 'wwid',
              label: 'WWID'
            }]
          })
        } else if (item.key == 'channelName') {
          this.searchs.push({
            label: '渠道',
            conditions: [],
            listUrl: this.$api.API_SELECT_CHANNEL_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.channelName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [
              {
                key:'channelName',
                name:'渠道名称',
                search:true,
                type:'text'
            },
            {
                key:'channelCode',
                name:'渠道代码',
                search:true,
                type:'text'
            }],
            columns: [{
              prop: 'channelName',
              label: '渠道名称'
            },{
              prop: 'channelCode',
              label: '渠道代码'
            }]
          })
        } else if (item.key == 'attrName') {
          this.searchs.push({
            label: '业务属性',
            conditions: [],
            listUrl: this.$api.API_SELECT_ATTR_LIST,
            selectItem: function (resp) {
              self.searchs.pop()
              // 回调
              if (typeof(callback) == 'function') {
                let data = {}
                data[item.key] = resp.attrName
                if (item.vkey) {
                  data[item.vkey] = resp.pkid
                }
                callback(data)
              }
            },
            items: [
              {
                key:'attrName',
                name:'业务属性名称',
                search:true,
                type:'text'
            },
            {
                key:'attrCode',
                name:'业务属性代码',
                search:true,
                type:'text'
            }],
            columns: [{
              prop: 'attrName',
              label: '业务属性名称'
            },{
              prop: 'attrCode',
              label: '业务属性代码'
            }]
          })
        }
        return;
      }
      this.$emit('search', item, (obj) => {
        // 已绑定的对象不允许动态添加属性，添加了也不会生成setter和getter
        let data = Object.assign({}, this.formData)
        data = Object.assign(data, obj)
        this.formData = data
      })
    },
    getSelectOption(item) {
      this.$emit('getSelectOption',item)
    },
    submit() {
      if (this.$refs.listView) {
        let conditions = this.cons ? this.cons : []
        for (let idx in this.condiItems) {
          let item = this.condiItems[idx]
          let value = item.vkey ? this.formData[item.vkey] : this.formData[item.key]
          if (item.checked) {
            conditions.push({
              checked: true,
              prop: item.vkey ? item.vkey : item.key,
              value: value
            })
          }
        }
        this.cons = conditions
      } else {
        for (let idx in this.condiItems) {
          let item = this.condiItems[idx]
          if (item.checked) {
            let value = item.vkey ? this.formData[item.vkey] : this.formData[item.key]
            if (value == undefined || value == 'undefined') {
              if (item.type == 'checkbox') {
                this.formData[item.key] = false
                this.formData[item.vkey] = false
              }
              if (item.type == 'text') {
                this.formData[item.key] = ''
                this.formData[item.vkey] = ''
              }
            }
          }
        }
        console.log(this.formData)
        this.$emit('submit',this.formData, this.condiItems)
      }
    },
    clear() {
      this.allchecked = false
      this.formData = {}
      this.cons = []
      let temp = []
      this.condiItems = this.condiItems.map(item=>{
        item.checked = false
        return item
      })
      this.$emit('submit',this.formData, this.condiItems)
    },
    searchBack() {
      if ((this.page == "customer" || this.page == "store") && this.searchs.length > 0) {
        this.searchs.pop()
        return;
      }
      this.$emit('searchBack')
    },
    tableSelect(row) {
      this.$emit('submit', row, this.condiItems)
    },
    selectOne(idx) {
      this.condiItems[idx].checked = true
    },
    selectAll(selected) {
      if (selected) {
        this.condiItems = this.condiItems.map(item=>{
          item.checked = true
          return item
        })
      }
    },
    formItemCheckChange(checked, index) {
      this.allchecked = false
      this.condiItems[index].checked = checked
    }
  },
  created() {
    this.condiItems = this.items.length > 0 ? this.items : (this.page == "customer" ? this.customerItems :(this.page == "store" ? this.storeItems : this.items))
    this.condiItems = this.condiItems.map(item=>{
      return Object.assign({checked: false}, item)
    })
  },
  components: {CommonList}
}
</script>

<style lang="css" scoped>
.main {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.search-container {
  position: relative;
  top: 0;
  display: block;
  width: 50%;
  height: 60%;
  background: white;
  border-radius: 5px;
  overflow: auto;
}
.search-container .title {
    font-size: 16px;
    font-weight: 600;
    color: #666666;
}
.search-container .operation {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-top: 30px
}
.search-container .form-item {
  width: 96%;
  margin: 5px 2%;
}
.search-container .close {
  position: fixed;
  margin: 0;
  display: flex;
  width: 50%;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  background: red;
  height: 30px;
  z-index: 99;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

.search-container .search-divider {
  margin: 0;
  margin-top: 5px;
  margin-bottom: 5px;
}

.search-container .search-checkbox {
  margin-left: 15px;
}

/deep/ .el-form-item__label {
    font-size: 13px;
    text-align: center;
}
/deep/ .table-head-cell{
  padding: 5px 0 !important;
  color: #000000 !important;
  font-size: 12px !important;
}

.el-button /deep/ span {
  display: inline-block;
}

/* .el-input__inner {
    padding-right: 300px;
} */
</style>
